package com.rdc.qingkou.presenter;

import android.util.Log;

import com.rdc.qingkou.contract.MessageContract;
import com.rdc.qingkou.entity.MessageNewsNumResult;
import com.rdc.qingkou.entity.MessageResult;
import com.rdc.qingkou.model.MessageModel;
import com.rdc.qingkou.model.imodel.OnHttpCallBack;

public class MessagePresenter implements MessageContract.IMessagePresenter{

    private MessageContract.IMessageModel mIMessageModel;   //M层
    private MessageContract.IMessageView mIMessageView;  //V层

    public Integer integer = 0;   //???

    /**
     * 获取未读消息数目
     */
    @Override
    public void getUnReadNewsNum(Integer userId) {

        mIMessageView.showProgress();   //通知V层显示对话框

        mIMessageModel.getUnReadNewsNum(userId,new OnHttpCallBack<MessageNewsNumResult>() {
            //有一个请求结果的回调,即我调用请求电影信息的方法了,M层要返回一个成功还是失败的信息给我

            @Override
            public void onSuccessful(MessageNewsNumResult messageNewsNumResult) {

                Log.d("MessagePresenter","onSuccessful");
                mIMessageView.hideProgress();
                mIMessageView.showUnReadNum(messageNewsNumResult);

            }

            @Override
            public void onFaild(String errorMsg) {

                Log.d("MessagePresenter","onFaild");

                mIMessageView.hideProgress();  //通知V层隐藏对话框
                mIMessageView.showInfo(errorMsg);   //通知V层显示错误信息

            }
        });
    }

    public MessagePresenter(MessageContract.IMessageView mIMessageView){
        this.mIMessageView = mIMessageView;
        mIMessageModel = new MessageModel();
    }

    /**
     * 获取未读消息
     */
    @Override
    public void getMessage(Integer userId,Integer currentPage) {

        mIMessageView.showProgress();   //通知V层显示对话框

        mIMessageModel.getMessage(userId,currentPage, new OnHttpCallBack<MessageResult>() {
        //有一个请求结果的回调,即我调用请求获取未读消息的方法了,M层要返回一个成功还是失败的信息给我

            @Override
            public void onSuccessful(MessageResult messageResult) {

                mIMessageView.hideProgress();
                mIMessageView.showData(messageResult);

            }

            @Override
            public void onFaild(String errorMsg) {

                mIMessageView.hideProgress();  //通知V层隐藏对话框
                mIMessageView.showInfo(errorMsg);   //通知V层显示错误信息

            }
        });

    }

    @Override
    public void loadMoreMessage(Integer userId , Integer currentPage) {
        //getMessage();

        mIMessageView.showProgress();   //通知V层显示对话框

        mIMessageModel.getMoreMessage(userId,currentPage, new OnHttpCallBack<MessageResult>() {
            //有一个请求结果的回调,即我调用请求获取未读消息的方法了,M层要返回一个成功还是失败的信息给我

            @Override
            public void onSuccessful(MessageResult messageResult) {

                mIMessageView.hideProgress();
                mIMessageView.showMoreMessage(messageResult);

            }

            @Override
            public void onFaild(String errorMsg) {

                mIMessageView.hideProgress();  //通知V层隐藏对话框
                mIMessageView.showInfo(errorMsg);   //通知V层显示错误信息

            }
        });
    }

    @Override
    public void getUpdateNews() {

    }
}
